
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="static/qui/libs/js/jquery.js"></script>
    <script type="text/javascript" src="static/qui/libs/js/language/cn.js"></script>
    <script type="text/javascript" src="static/qui/libs/js/framework.js"></script>
    <link href="static/qui/libs/css/import_basic.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" id="skin" prePath="static/qui/" />
    <link rel="stylesheet" type="text/css" id="customSkin" />
    <script type="text/javascript" src="static/qui/libs/js/popup/toast.js"></script>
    <script src="static/qui/libs/js/table/quiGrid.js" type="text/javascript"></script>
</head>
<body>
<div class="page_content">
    <button type="button" onclick="add()"><span class="icon_add">新增</span></button>
    <div class="groupTitle"><span>寝室列表</span></div>
    <div class="img_list_win">
        <ul class="clearfloat">

        </ul>
    </div>
</div>
<script>
    function getQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r!=null) return decodeURI(r[2]);
        return "";
    }
    function add() {
        var diag = new top.Dialog();
        diag.Title = "新增";
        diag.URL = "rootManageForm.jsp?flag=add";
        diag.Width=600;
        diag.Height=400;
        diag.OkButtonText = "保存";
        diag.OKEvent = function() {
            diag.innerFrame.contentWindow.submitHandler(0);
        };
        diag.show();
    }

    function  initComplete() {
        $(".clearfloat").html("");
        $.getJSON("/rootManage/getAllData",{"audit":getQueryString("audit")},function (data) {
            for(var i=0;i<data.length;i++){
               var html="";
                html+='<li>';
                html+='  <img src="/upload'+data[i].roomImg+'"/>';
                html+='     <p>'+data[i].roomNumber+'</p>';
                html+='      <div class="edit_delete" style="text-align: center;width:100%;">';
                if(!data[i].audit){
                    html+='  <span onclick="auditPass('+data[i].id+')">审核通过&nbsp;&nbsp;</span><span onclick="deleteData('+data[i].id+')">删除</span>';
                }
                else if(data[i].beginScore&&data[i].endScore){
                    html+='<span>实地分：'+data[i].beginScore+'&nbsp;&nbsp;评分：'+data[i].endScore+'&nbsp;&nbsp;</span><span onclick="deleteData('+data[i].id+')">删除</span>';
                }
                else{
                    html+='<span onclick="toScore('+data[i].id+')">评分&nbsp;&nbsp;</span><span onclick="deleteData('+data[i].id+')">删除</span>';
                }
                html+='    </div>';
                html+='   </li>';
                $(".clearfloat").append(html)
            }
        })
    }

    function auditPass(id) {
        top.Dialog.confirm("确认吗？",function(){
            $.post("/rootManage/updateData",{"id":id},function (data) {
                if(data.success){
                    initComplete();
                }
                else{
                    top.Toast('showWarningToast', data.msg);
                }
            });
        });
    }

    function refresh(){
        initComplete();
    }
    
    function toScore(id) {
        var diag = new top.Dialog();
        diag.Title = "评分";
        diag.URL = "toScore.jsp?flag=add&id="+id;
        diag.Width=600;
        diag.Height=400;
        diag.OkButtonText = "保存";
        diag.OKEvent = function() {
            diag.innerFrame.contentWindow.submitHandler(0);
        };
        diag.show();
    }

    function deleteData(id) {
     top.Dialog.confirm("确认删除吗？",function(){
            $.post("/rootManage/deleteData",{"id":id},function (data) {
                if(data.success){
                    initComplete();
                }
                else{
                    top.Toast('showWarningToast', data.msg);
                }
            });
        });
    }
</script>
</body>
</html>
